<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<script src="../vue.js"></script>

<body>
  <div id="app">
    <parent></parent>
  </div>

  <!-- 子组件模板 -->
  <template id="child-template">
    <div>
      <button @click="clickButton">发送</button>
      <input type="text" v-model="message">
    </div>
  </template>

  <!-- 父组件模板 -->
  <template id="parent">
    <div>
      <child @childfn="transContent"></child>子组件传来的值：{{message}}
    </div>
  </template>

  <script>
    // 注册父组件
    Vue.component("parent", {
      data() {
        return {
          message: "",
        }
      },
      // template: '<div> <child @childfn="transContent"></child> ' + '子组件传来的值：{{message}} </div>',
      template: "#parent",
      methods: {
        transContent(value) {
          this.message = value;
        }
      }
    })

    // 注册子组件
    Vue.component("child", {
      data() {
        return {
          // 即将发送的数据
          message: "子组件的消息。",
        }
      },
      template: "#child-template",
      methods: {
        clickButton() {
          this.$emit("childfn", this.message);
        }
      }
    })


    const vm = new Vue({
      el: "#app"
    })
  </script>
</body>

</html>